/**
 * @Author:  renyc
 * @Date: 2022年12月20日23:27:28
 */

import * as Cesium from "cesium/Cesium";
import Util from "../../utils/Util";
import PrimitiveOverlay from "./PrimitiveOverlay";

class PolylinePrimitive extends PrimitiveOverlay{

    constructor(coordinates, options){
        super();
        this._coordinates = coordinates;
        this._options = options;
        this._delegate = undefined;

        if(this._coordinates){
            this._delegate = this._createPrimivive();
        }
    }

    _createPrimivive(){
        // let coordiates = [
        //     0.0, 0.0,
        //     5.0, 0.0,
        //     5.0, 5.0
        // ];
        let coordiates = this._coordinates;
        let polyline = new Cesium.PolylineGeometry({
            id: this._id,    
            positions : Cesium.Cartesian3.fromDegreesArray(coordiates),
            width : 10.0,
            vertexFormat : Cesium.PolylineMaterialAppearance.VERTEX_FORMAT,
            clampToGround : true
        });
        //let solidWhite = Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.WHITE);

        let geometryInstance = new Cesium.GeometryInstance({
            id : Util.uuid(),
            geometry : polyline
            // attributes : {
            //     color : solidWhite
            // }
        });
        geometryInstance.delegate = this._delegate;

        //2. 创建Apperance实例
        let appearance = new Cesium.PolylineMaterialAppearance({
            material : Cesium.Material.fromType('Color')
        });

        let primitive = new Cesium.Primitive({
            // 利用新创建的instance为Primitive的geometryInstance属性赋值
            geometryInstances: geometryInstance,
            // 定义instance的apperance
            appearance: appearance,
        });

        return primitive;


    }
}

export default PolylinePrimitive
